function AllReady() {
	var mstform = Ext.getCmp("CntChangeM7"); //获取容器
	var PhidCnt = mstform.queryById("PhidCnt");
	var PhidPc = mstform.queryById("PhidPc");
	var user_division = mstform.queryById("user_division"); //获取字段---事业部
	var user_regional_center = mstform.queryById("user_regional_center"); //区域中心
	var OriPhidDept = mstform.queryById("OriPhidDept");
	var PhidBuyer = mstform.queryById("PhidBuyer");
	var user_ywlx = mstform.queryById("user_ywlx");
	var user_product_line = mstform.queryById("user_product_line");
	var user_pro_type = mstform.queryById("user_pro_type ");
	var user_business_type = mstform.queryById("user_business_type");
	var user_purchaser = mstform.queryById("user_purchaser");
	var OriCntTitle = mstform.queryById("OriCntTitle");
	var Title = mstform.queryById("Title");
    var toolbar = Ext.getCmp('toolbar');
    toolbar.get('imp').setText('引用采购合同')
    let itemtab_innerCt = null;
    let itemtab_innerCt_tabtool = null
    let winLock = 0
    //获取条款信息明细信息
    var tabbtn = Ext.getElementById(Ext.getElementById(Ext.getElementById(Ext.getElementById(Ext.getElementById(Ext.getElementById("tabPanel").children[0].id).children[0].id).children[1].id).children[0].id).children[1].id)
    console.log(tabbtn);

    //给表体默认值
    Title.setValue("采购合同变更")
    Title.hide()
    //追加点击事件逻辑
    tabbtn.addEventListener('click',(event)=>{
      //禁用
    //   return
        // console.log(`点击成功`);
        window.timeLock = setInterval(() => {
			try {
				// 获取弹窗
				

                //获取容器
				itemtab_innerCt = Ext.getCmp(
					Ext.getElementById(
						Ext.getElementById(
							Ext.getElementById(
								Ext.getElementById("itemtab-innerCt")
									.children[0].id
							).children[0].id
						).children[0].id
					).children[0].id
				);
                //获取按工具栏
                itemtab_innerCt_tabtool = Ext.getCmp(
                    Ext.getElementById(Ext.getElementById(
						Ext.getElementById(
							Ext.getElementById(
								Ext.getElementById("itemtab-innerCt")
									.children[0].id
							).children[0].id
						).children[0].id
					).children[0].id).children[0].id
                )
                // itemtab_innerCt_tabtool.insert(1, { itemId: "oriCntPayInfo", text: "引用合同预收预付", width: this.itemWidth, iconCls: "icon-AddBrother" })
                // 隐藏原有相同功能按钮
                // itemtab_innerCt_tabtool.get("addrel").hide()
                // 获取按钮信息
                const btn = itemtab_innerCt_tabtool.get("oriCntPayInfo")
                //生成点击事件
                // console.log(`按钮信息`,btn);
                btn.on("click",function(){
                    // console.log(`按钮被点击啦`);
                    // 点击触发事件
                    openCntPayDetail()
                })
                //增加事件编辑监听
                itemtab_innerCt.on("edit",()=>{
                    const _data = itemtab_innerCt.getStore()
                    _data.each((item)=>{
                        console.log(`变更后金额计算`,item.get("BalPercentNew"),((Number(item.get("BalPercentNew")) || 0) * (Number(mstform.queryById("NewCntAmtFc")) || 0)).toFixed(2));
                        item.set("BalAmtFcNew",((Number(item.get("BalPercentNew")) || 0) * (Number(mstform.queryById("NewCntAmtFc").getValue()) || 0)).toFixed(6)) 
                    })
                    itemtab_innerCt.getView().refresh()
    			})
				clearInterval(window.timeLock);
                // console.log(itemtab_innerCt,itemtab_innerCt_tabtool);
			} catch (e) {
            }
		}, 200);

        if(winLock){
            clearInterval(winLock)
        }
		winLock = setInterval(()=>{
			try{
				let arr= [1,0,0,0,0]
                let dom = document.querySelector(".x-window")
                let windowId = dom.id
                let Box = Ext.getCmp(windowId)
                if(Box.title == '合同预收预付参数选择'){
                    clearInterval(winLock)
                    var win = getElementId(arr,dom)
                    console.log(`弹窗`,win,Box);
                    let contentBox = Ext.getCmp(win)
                    const rowDatas = contentBox.getStore()
                    console.log(`全部数据`,rowDatas);
                    rowDatas.each(item=>{
                        console.log(`Phid`,item.get("PhId"));
                        if(item.get("PhId")){
                            // 查询其他自定义字段
                            execServer("getCntYsyfInfo",{phid:item.get("PhId")},(res)=>{
                                console.log(res);
                                if(res.count == 0) return
                                const _data = JSON.parse(res.data)[0].extendObjects
                                console.log(`预收预付信息`,_data);
                                item.set("Name",_data.name_new)
                                item.set("NameNew",_data.name_new)
                                item.set("user_zffs",_data.user_zffs)
                                item.set("user_bghzffs",_data.user_zffs)
                                item.set("user_xzzq",_data.user_xzzq)
                                item.set("user_bghxzzq",_data.user_xzzq)
                                item.set("user_zbqs_dt",_data.user_zbqs_dt)
                                item.set("user_bghzbqssj",_data.user_zbqs_dt)
                                item.set("user_hp_dt",_data.user_hp_dt)
                                item.set("user_bghhpsj",_data.user_hp_dt)
                                item.set("user_fktj",_data.user_fktj)
                                item.set("user_bghfktj",_data.user_fktj)
                                item.set("user_zfjsjs",_data.user_zfjsjs)
                                item.set("bal_percent_new",_data.bal_percent)
                                contentBox.getView().refresh()
                            })
                        }
                    })
                    clearInterval(winLock)
                }
			} catch(e) {
				console.log(e);
			}
		},1000)
    })
	function getElementId(arr,element){
		return arr.reduce((value,item)=>{
			value = Ext.getElementById(value.children[item].id)
			return value
		},element).id
	}
    // 引用预付帮助事件
    function openCntPayDetail(){
        if(! mstform.queryById("PhidCnt").getValue()){
            Ext.Msg.alert("提示","未选中变更合同")
            return
        }
        var help = Ext.create('Ext.ng.MultiRichHelp', {
            valueField: 'phid',   //代码列
            displayField: 'name',  //名称列
            helpid: 'cghtzftk',         //获取帮助ID
            ORMMode: false,
            outFilter: {
                'phid_cnt': mstform.queryById("PhidCnt").getValue()
            } //判断条件，因为该通用帮助的两张表中均有phid列，因此需声明取哪张表的phid列，若列唯一可以直接写为phid(无需引号)	 
        });
        help.showHelp();
        help.on('helpselected', function (obj) {
            // console.log(`预收预付帮助数据`,obj);
            // 将数据全部添加到预收预付
            const _data = obj.data
            const _arr = _data.reduce((value,item)=>{
                value.push(
                    {
                        Name:item.get("name_new"),
                        NameNew:item.get("name_new"),
                        user_zffs:item.get("user_zffs"),
                        user_bghzffs:item.get("user_zffs"),
                        user_xzzq:item.get("user_xzzq"),
                        user_bghxzzq:item.get("user_xzzq"),
                        user_zbqs_dt:item.get("user_zbqs_dt"),
                        user_bghzbqssj:item.get("user_zbqs_dt"),
                        user_hp_dt:item.get("user_hp_dt"),
                        user_bghhpsj:item.get("user_hp_dt"),
                        user_fktj:item.get("user_fktj"),
                        user_bghfktj:item.get("user_fktj"),
                        user_zfjsjs:item.get("user_zfjsjs"),
                        BalAmtFc:item.get("bal_amt_fc"),
                        BalAmtFcNew:item.get("bal_amt_fc"),
                        BalPercent:item.get("bal_percent"),
                        BalPercentNew:item.get("bal_percent"),
                        user_bghzfjsjs:item.get("user_zfjsjs"),
						PhidItem:"8570000000000001",
						PhidItemNew:"8570000000000001",
						PhidRelItem:String(item.get("phid")),
						OperFlg:"cnt_change",
                    }
                )
                return value
            },[])
            // console.log(`数据准备`,_arr,itemtab_innerCt.getStore().getCount());
            itemtab_innerCt.getStore().insert(itemtab_innerCt.getStore().getCount(),_arr)
            itemtab_innerCt.getView().refresh()
        })
    }
	if (mstform) {
		if (PhidPc.getValue()) {
			// console.log("PhidPc", PhidPc.getValue());
			execServer(
				"getPtInfoByPhid",
				{ phid: PhidPc.getValue() },
				function (res) {
					const datas = JSON.parse(res.data)[0].extendObjects;
					//帮助字段赋值
					// console.log(datas, "datas");
					user_division.setValue(datas.division_phid);
					user_product_line.setValue(datas.midwife_phid);
					user_regional_center.setValue(datas.regional_center_phid);
					BatchBindCombox([user_division]);
					BatchBindCombox([user_product_line]);
					BatchBindCombox([user_regional_center]);
				}
			);
		}
	}
	OriCntTitle.addListener("change", function (args) {
		Title.setValue(OriCntTitle.getValue());
	});
	PhidCnt.addListener("helpselected", function () {
		execServer("getCntInfo", { cnt: PhidCnt.getValue() }, function (res) {
			execServer("getCntInfo", { cnt: PhidCnt.getValue() }, function (res) {
				const datasGetCntInfo = JSON.parse(res.data)[0].extendObjects;
				if (datasGetCntInfo) {
					if (datasGetCntInfo.pc) {
						PhidPc.setValue(datasGetCntInfo?.pc);
						BatchBindCombox([PhidPc]);
					}
					if (datasGetCntInfo.upt) {
						user_pro_type.setValue(datasGetCntInfo.upt);
					}
					if (datasGetCntInfo.ubt) {
						// user_ywlx.setValue(datasGetCntInfo.ubt);
						// BatchBindCombox([user_ywlx]);
					}
					if (datasGetCntInfo.up) {
						user_purchaser.setValue(datasGetCntInfo.up);
						BatchBindCombox([user_purchaser]);
					}
				}
			});
		});
	});
	PhidPc.addListener("change", function (args) {
		if (PhidPc.getValue()) {
			execServer(
				"getPtInfoByPhid",
				{ phid: PhidPc.getValue() },
				function (res) {
					const datas = JSON.parse(res.data)[0].extendObjects;
					//帮助字段赋值
					// console.log(datas, "datas");
					user_division.setValue(datas.division_phid);
					user_product_line.setValue(datas.midwife_phid);
					user_regional_center.setValue(datas.regional_center_phid);
					BatchBindCombox([user_division]);
					BatchBindCombox([user_product_line]);
					BatchBindCombox([user_regional_center]);
				}
			);
			if (!PhidCnt.getValue()) return;
			execServer(
				"getCntMInfoByPhid",
				{ phid: PhidCnt.getValue() },
				function (res) {
					try {
						const datasGetCntMInfoByPhid = JSON.parse(res.data)[0]
							.extendObjects;
						//帮助字段赋值
						// console.log(datasGetCntMInfoByPhid, "getCntMInfoByPhid");
						OriPhidDept.setValue(datasGetCntMInfoByPhid.dept_phid);
						BatchBindCombox([OriPhidDept]);
						// user_gys.setValue(datasGetCntMInfoByPhid.supply_id);
						// BatchBindCombox([user_gys]);
					} catch (error) {}
				}
			);
		}
	});
	var dgrid = Ext.getCmp("CntChangeD7");
	var dstore = dgrid.store;

	dgrid.addListener("edit", function (editor, e) {
		var record = e.record;
		if (e.originalValue == e.value) {
			return;
		}
		try {
			if (record.data.QtyNew > record.data.QtyOld) {
				record.set("QtyNew", record.data.QtyOld);
				Ext.Msg.alert("提示", "新采购数量不能大于原采购数量");
			}
		} catch (error) {
			// console.error(error);
		}
	});
	if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
		dstore.on("datachanged", async function (dstore, eOpts) {
			const records = dstore.getRange();
			for (const record of records) {
				try {
					if (record.data.QtyNew > record.data.QtyOld) {
						record.set("QtyNew", record.data.QtyOld);
						Ext.Msg.alert("提示", "新采购数量不能大于原采购数量");
					}
				} catch (error) {
					// console.error(error);
				}
			}
		});
	}
    
    //根据id获取原合同条款信息
    function getCgCntInfoPayDetail(){

    }
}//END AllReady
